#pragma once

#include "myPubFunc.h"
#include "CPubFunc.h"
#include <mzfc_inc.h>
#include "md5.h"

bool myPassword::passwordvalid()
{
	bool isvalid = false;
	CppSQLite3DB mydb;
	mydb.open(UnicodeToUTF8(DATABASE_NAME));
	CppSQLite3Query q = mydb.execQuery("select PasswordIsValid from info;");
	/*
	for (int fld = 0; fld < q.numFields(); fld++)
	{
	const char * a = q.fieldName(fld);
	const char* b = q.fieldDeclType(fld);

	}
	*/
	while (!q.eof())
	{
		isvalid=atoi(q.fieldValue(0));
		q.nextRow();
	}
	mydb.close();
	return isvalid;
}

bool myPassword::checkpassword( char* input )
{
	string passbymd5 =MD5(input).toString();
	/*test
	char  a[64];
	sprintf(a,"%s",passbymd5.c_str());*/

	string strpasswordMD5;
	CppSQLite3DB mydb;
	mydb.open(UnicodeToUTF8(DATABASE_NAME));
	CppSQLite3Query q = mydb.execQuery("select PasswordMD5 from info;");
	while (!q.eof())
	{
		strpasswordMD5=q.fieldValue(0);
		/*test
		char  b[64];
		sprintf(b,"%s",strpasswordMD5.c_str());*/
		q.nextRow();
	}
	mydb.close();

	if (passbymd5 == strpasswordMD5)
	{
		return true;
	}
	else
		return false;

}